package com.itheima.reggie;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.event.EventListener;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.io.IOException;

@EnableCaching//开启基于缓存的注解
@SpringBootApplication  //启动类
@MapperScan("com.itheima.reggie.mapper")    //扫描mybatis接口创建代理对象
@EnableTransactionManagement    //开启事务注解支持
@Slf4j  //日志
public class WebManageApplication {

    @Value("${server.port}")
    private String appport;  //获取站点端口号

    @Value("/backend/page/login/login.html")
    private String path;    //指定访问路径


    public static void main(String[] args) {
        SpringApplication.run(WebManageApplication.class, args);
        log.info("WebManage项目启动成功");

    }

    /*当端口启动后，直接跳转界面*/
    @EventListener({ApplicationReadyEvent.class})
    void applicationReadyEvent() {
        //指定浏览器路径
        String cmd = "D:\\Google\\Chrome\\Application\\chrome.exe";
        //需要在浏览器路径和网址间加空格，以此分辨路径
        //网址路径
        String url = " http://localhost:" + appport + path;

        Runtime runtime = Runtime.getRuntime();
        try {
            //使用指定浏览器加载
            runtime.exec(cmd + url);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

